<?php

 class Site {

     public $sqlPost = "SELECT 
                                        cl.idcolaborador,
                                        cl.nomecolaborador,
                                        cl.ramalcolaborador,
                                        st.nomesetor,
                                        fc.nomefuncao
                                FROM
                                        colaborador cl,
                                        setor st,
                                        funcao fc
                               WHERE
		cl.setor_idsetor = st.idsetor AND
                                       cl.funcao_idfuncao = fc.idfuncao";

     public
             function listaColaborador1( $pdo ) {
         $obj = $pdo->prepare( "SELECT idcolaborador, nomecolaborador, ramalcolaborador, nomesetor FROM colaborador, setor WHERE setor_idsetor = idsetor order by nomecolaborador" );
         return ($obj->execute()) ? $obj : false;
     }

     public
             function listaSetor( $pdo ) {
         $obj = $pdo->prepare( "SELECT idsetor, nomesetor FROM setor order by nomesetor" );
         return ($obj->execute()) ? $obj : false;
     }

     public
             function listaColaborador( $pdo, $idsetor = null ) {
         $where = " ";


         if ( $idsetor != null )
             $where .= " AND cl.setor_idsetor = $idsetor ";

         $obj = $pdo->prepare( $this->sqlPost . " " . $where );

         $obj->execute();
         return $obj;
     }

     public
             function getPost( $pdo, $postid, $url = null ) {
         if ( $url == null ) {
             $where = " AND bp.postid = :postid ";
             $obj   = $pdo->prepare( $this->sqlPost . " " . $where );
             $obj->bindParam( ":postid", $postid );
         }
         else {
             $where = " AND bp.posturlamigavel = :url ";
             $obj   = $pdo->prepare( $this->sqlPost . " " . $where );
             $obj->bindParam( ":url", $url );
         }

         return ($obj->execute()) ? $obj->fetch( PDO::FETCH_OBJ ) : false;
     }

     public
             function listaImagensPost( $pdo, $postid, $destaque = "NI" ) {

         $sql   = "SELECT * FROM blog_imagem WHERE blog_post_postid = :postid  ";
         $where = "";

         if ( $destaque != "NI" )
             $where = " AND imagemdestaque = " . $destaque . " ";

         $obj = $pdo->prepare( $sql . " " . $where );
         $obj->bindParam( ":postid", $postid );
         $obj->execute();
         return $obj;
     }

 }
 